﻿
Imports System.IO
Imports xmlctrl
Imports xhtmlctrl
Imports webctrl

Public Class music
    Inherits requestProcessor

    Public Const _pathidentity As String = "/music"

    Public Overrides Function pathidentity() As String
        Return _pathidentity
    End Function

    Public Overrides Function process(ByVal context As httpContext) As Boolean
        Dim buff As MemoryStream = Nothing
        buff = context.buff()

        Dim page As xhtmlpage = Nothing
        page = New xhtmlpage(buff)
        page.body().id = "id_image"
        page.title().text = applicationSign() + " - music"

        Dim csslink As csslink = Nothing
        csslink = New csslink(buff)
        csslink.href = csslinkhref
        page.head().addchild(csslink)

        Dim div As div = Nothing
        div = New div(buff)
        div.id = "id_player"
        page.body().addchild(div)

        Dim link As String = Nothing
        link = config.parameter(configNaming.music.name, configNaming.music.link _
                                    , configNaming.defaultValue.music.link)
        If context.isIEUserAgent() Then
            Dim wmp As wmp = Nothing
            wmp = New wmp(buff)
            div.addchild(wmp)
            wmp.addurl(link)
            wmp.addAutoStart("-1")
            wmp.addplaycount(4294967296 / 2 - 1)
            wmp.addvolume("100")
        Else
            Dim obj As [object] = Nothing
            obj = New [object](buff)
            obj.data = link
            obj.type = network.http.contentType.audiomp3
            div.addchild(obj)

            Dim param As param = Nothing
            param = New param(buff)
            param.name = "src"
            param.value = link
            obj.addchild(param)
        End If

        Dim reloader As reloader = Nothing
        reloader = New reloader(buff)
        reloader.id = "id_reload"
        reloader.text = "try another music"
        page.body().addchild(reloader)

        context.setstatuscode(Net.HttpStatusCode.OK, "OK")
        context.setcontentEncoding(encoding.utf8)
        context.setcontentType(network.http.contentType.texthtmlUtf8)

        If page.render() Then
            Return True
        Else
            raiseError("cannot render xhtmlpage.", errorHandle.errorType.warning)
            Return False
        End If
    End Function
End Class
